import request from '../utils/request'
// import store from '../store'
// 登录接口
const loginAPI = ({ mobile, code }) => { // 都用对象且，跟后台的一致，方便传值
  return request({
    method: 'post',
    url: '/v1_0/authorizations',
    data: {
      mobile,
      code
    }
  })
}
// 用户已选频道列表
const getUserChannelsListAPI = () => {
  return request({
    method: 'get',
    url: '/v1_0/user/channels'
    // headers: {
    //   Authorization: `Bearer +${store.state.token}`
    // }
  })
}
// 文章列表
const getArticleListAPI = ({ channelId, timestamp }) => {
  return request({
    method: 'get',
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp: timestamp || (new Date()).getTime()
    }
  })
}
// 不感兴趣文章
const articleDislikeAPI = ({ artId }) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`
    // },
    data: {
      target: artId
    }

  })
}
// 反馈垃圾内容，文章举报
const articleReportsAPI = ({ artId, type, remark }) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/reports',
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`
    // },
    data: {
      target: artId,
      type, // 值与键一致
      remark: type === '0' ? remark : remark || null
    }
  })
}
// ************************************************所有频道
const getAllChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}
// ****************************************************更新用户选择频道
const updateUserChannelListAPI = ({ channels }) => {
  return request({
    method: 'put', // 全局修改
    url: '/v1_0/user/channels',
    // 因为channel里带id,seq
    data: {
      channels

    }

  })
}
export { loginAPI, getUserChannelsListAPI, getArticleListAPI, articleDislikeAPI, articleReportsAPI, getAllChannelListAPI, updateUserChannelListAPI }
